<template>
    <div>
        <!-- 条件查询 -->
        <el-row>
          <el-col :span="24"><div class="grid-content bg-purple-dark">
              <el-form :inline="true" :model="searchData" class="demo-form-inline">
                <el-form-item label="年级" :label-width="formLabelWidth">
                    <el-select v-model="searchData.grade" placeholder="请选择">
                      <el-option
                        v-for="item in grade"
                        :key="item.dictValue"
                        :label="item.dictLabel"
                        :value="item.dictValue">
                      </el-option>
                    </el-select>
                </el-form-item>
                  <el-button type="primary" @click="searchTasks">查询</el-button>
              </el-form>
              </div></el-col>
        </el-row>


        <!-- 查询表格 -->
        <el-row>
          <el-col :span="24"><div class="grid-content bg-purple-dark">
              <el-table :data="findTaskData" height="550">
                <el-table-column prop="id" label="Id"></el-table-column>
                <el-table-column prop="taskTitle" label="标题"></el-table-column>
                <el-table-column prop="grade" label="学级">
                    <template slot-scope="scope">
                        <span v-if="scope.row.grade ==0">一年级</span>
                        <span v-if="scope.row.grade ==1">二年级</span>
                        <span v-if="scope.row.grade ==2">三年级</span>
                        <span v-if="scope.row.grade ==3">四年级</span>
                        <span v-if="scope.row.grade ==4">五年级</span>
                        <span v-if="scope.row.grade ==5">六年级</span>
                        <span v-if="scope.row.grade ==6">初一</span>
                        <span v-if="scope.row.grade ==7">初二</span>
                        <span v-if="scope.row.grade ==8">初三</span>
                        <span v-if="scope.row.grade ==9">高一</span>
                        <span v-if="scope.row.grade ==10">高二</span>
                        <span v-if="scope.row.grade ==11">高三</span>
                    </template>
                </el-table-column>
                <el-table-column prop="createName" label="发送人"></el-table-column>
                <el-table-column prop="createTime" label="创建时间"></el-table-column>
                <el-table-column label="操作" width="260">
                    <template slot-scope="scope">
                        <el-button size="small" @click="getTask(scope.row)" plain>编辑</el-button>
                        <el-button type="danger" size="small" @click="delTask(scope.row)" plain>删除</el-button>
                    </template>
                </el-table-column>
              </el-table>

            <!-- 分页 -->
            <div class="block">
                <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageNum"
                :page-sizes="[2, 4, 6, 8]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total" style="float:right">
                </el-pagination>
            </div>
              </div></el-col>
        </el-row>
    </div>
</template>

<script>
import axios from 'axios';
export default {
    data(){
        return{
            pageNum:1,
            pageSize:2,
            total:null,
            findTaskData:[],
            searchData:{
                "grade":""
            },
            grade:[],           //查询字典年级表临时变量
        }
    },
    created(){
        this.initTable();
        this.searchDict()
    },
    methods:{

        getTask(row){
            //跳页面并带id
            sessionStorage.setItem("id",row.id);
            this.$router.push("/gg")
        },
        //删除
        delTask(row){
            axios.delete("/api/task/delTaskById?id="+row.id).then(res=>{
                this.$message({
                  message: res.data.message,
                  type: 'success'
                });
                this.initTable();
            })
        },
        //条件查询
        searchTasks(){
            this.searchDict()
            this.initTable();
        },
        //查询年级字典表
        searchDict(){
           axios.get("/api/dict/findDictDataByDictTypeIdSysUserSex?dictType=sys_grade_status").then(res=>{
             this.grade =res.data.data
           })
        },
        //查询
        initTable(){
            axios.post("/api/task/findTaskPaginationList?pageNum="+this.pageNum + "&pageSize=" +this.pageSize,this.searchData)
            .then(res=>{
                this.findTaskData = res.data.data.items
                this.total =res.data.data.totalElements
            })
        },
        //分页
        handleSizeChange(val) {
          this.pageSize = val;
          console.log(`每页 ${val} 条`);
          this.initTable();
        },
        handleCurrentChange(val) {
          this.pageNum = val;
          console.log(`当前页: ${val}`);
           this.initTable()
        },
    }
    
}
</script>


<style scoped>

</style>